package com.cloud.logger.zchain.zchainclient.http;


import com.alibaba.fastjson.JSONObject;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpPut;


/**
 * Created by Administrator on 2017/12/12.
 */
public class ObjectConversion<T> {

    //map和对象可以用这个方法进行转换
    public JSONObject personToObject(T map) {
        if (map == null) {
            return null;
        }
       // JSONObject jsonObject = JSONObject.fromObject(map);
       // System.out.println(jsonObject);
        return null;
    }

    //判断是否八大基本类型
    public static boolean setBasicType(String typeNeed) {
        String list = "String,Inter,Shot,Long,Float,Double,Char,Boolean,Byte";
        return (list.indexOf(typeNeed) >= 0) ? true : false;
    }

    //在泛型里面添加String类型
    public T genericAddResult(T requestDataMessage, String result) {
        //怎么将str1放到T里面去
        Object resultFinal = JSONObject.parseObject(result, requestDataMessage.getClass());
        return (T) resultFinal;
    }

    //判断执行哪个方法
    public static String returnDataRequest(String method, String url, JSONObject jSONObject) {
        RestClientTemplate restClientTemplate = new RestClientTemplate();
        String result = null;
        if (method.equals("doPut")) {
            HttpPut httpCurrency = new HttpPut(url);
            result = restClientTemplate.getResult(httpCurrency, jSONObject);
        }
        if (method.equals("main")) {
            HttpDelete httpCurrency = new HttpDelete(url);
            httpCurrency.setHeader("Content-Type", "application/json");
            result = restClientTemplate.getResult(httpCurrency, jSONObject);
        }
        if (method.equals("doPatch")) {
            HttpPatch httpCurrency = new HttpPatch(url);
            result = restClientTemplate.getResult(httpCurrency, jSONObject);
        }
        if (method.equals("HEADER ")) {

        }
        if (method.equals("OPTIONS ")) {

        }
        if (method.equals("TRACE ")) {

        }
        if (method.equals("CONNECT ")) {

        }
        return result;
    }

}
